//
//  SEGPublishHouseListViewModel.m
//  Commom
//
//  Created by 梁学彰 on 2020/6/4.
//

#import "SEGPublishHouseListViewModel.h"
#import "SEGPublishHouseViewModel.h"
#import "SEGPublishHouseTagViewModel.h"
#import "SEGImageChooseViewModel.h"
@implementation SEGPublishHouseListViewModel

#pragma mark - life cycle
- (instancetype)init {
    if (self = [super init]) {
        [self initData];
    }
    return self;
}

- (void)dealloc {
    
}

#pragma mark - init
- (void)initData {
    _requestParams = [NSMutableDictionary dictionary];
    _imageData = [NSArray array];
    _selectedTags = [NSArray array];
    _selectedData = [NSDictionary dictionary];
}




#pragma mark - send request
- (RACSignal *)loadDataWithSignal {
    //发布
    if (self.reantType == SEGEnumReantType_Publish) {
        return [self loadData];
    }
    
    // 编辑
    if (self.reantType == SEGEnumReantType_Edit) {
        //以前的数据
        RACSignal *editDataSignal = [self loadEditData];
        //公共的数据
        RACSignal *commonSignal = [self loadData];
        
        RACSignal *signal = [RACSignal concat:@[editDataSignal,commonSignal]];
        return signal;
    }
    //不存在其他情况
    return nil;
}

- (RACSignal *)loadEditData {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        // 编辑
        if (!(self.rentalId && self.rentalId.length > 0)) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"房屋租售主键ID不能为空！"}]];
        }
        
        if (self.type == SEGEnumPublishHouseTypeZL) { // 租赁
            [[SEGDetailsellManager sharedManager] requestDetailLeaseWithRentalid:self.rentalId finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                if (!isSuccessed) {
                    [subscriber sendError:[NSError errorWithDomain:errorMessage code:100 userInfo:nil]];
                }
                [subscriber sendCompleted];
            }];
        }
        if (self.type == SEGEnumPublishHouseTypeCS) { // 出售
            [[SEGDetailsellManager sharedManager] requestDetailsellWithRentalid:self.rentalId finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                if (!isSuccessed) {
                    [subscriber sendError:[NSError errorWithDomain:errorMessage code:100 userInfo:nil]];
                }
                [subscriber sendCompleted];
            }];
        }
        return nil;
    }];
    return signal;
}

- (RACSignal *)loadData {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        /* 装修程度：decorationLevel  押金模式：depositMode 入住时间：checkInTime 房屋设施：houseFacility）*/
        [[SEGQuerydictlistManager sharedManager] requestQuerydictlistWithType:@"checkInTime,depositMode,decorationLevel,houseFacility" finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            if (!isSuccessed) {
                [subscriber sendError:[NSError errorWithDomain:errorMessage code:100 userInfo:nil]];
                
            }
            
            // 对字典数据进行区分绑定
            NSMutableArray<SEGQuerydictlistDictlistModel*> *checkInTime = [NSMutableArray array];
            NSMutableArray<SEGQuerydictlistDictlistModel*> *depositMode = [NSMutableArray array];
            NSMutableArray<SEGQuerydictlistDictlistModel*> *decorationLevel = [NSMutableArray array];
            NSMutableArray<SEGQuerydictlistDictlistModel*> *houseFacility = [NSMutableArray array];
            [[SEGQuerydictlistManager sharedManager].queryDictList.data.dictList enumerateObjectsUsingBlock:^(SEGQuerydictlistDictlistModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj.type isEqualToString:@"checkInTime"]) [checkInTime addObject:obj];
                if ([obj.type isEqualToString:@"depositMode"]) [depositMode addObject:obj];
                if ([obj.type isEqualToString:@"decorationLevel"]) [decorationLevel addObject:obj];
                if ([obj.type isEqualToString:@"houseFacility"]) [houseFacility addObject:obj];
            }];
            self.selectedData = @{@"checkInTime":checkInTime,@"depositMode":depositMode,@"decorationLevel":decorationLevel,@"houseFacility":houseFacility};
            [self creatCellData];
            [subscriber sendCompleted];
        }];
        
        
        return nil;
    }];
    return signal;
}

- (RACSignal *)sendSaveRequest {
    
    //检查
    RACSignal *checkParamsSignal = [self checkParams];
    //发送
    RACSignal *sendSignal = [self sendRequet];
    
    RACSignal *signal = [RACSignal concat:@[checkParamsSignal,sendSignal]];
    return signal;
}

- (RACSignal * )sendRequet {
    
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        NSString *imageStr = [self.imageData componentsJoinedByString:@","];
        [self.requestParams setValue:imageStr forKey:@"housePhoto"];
        
        if(self.type == SEGEnumPublishHouseTypeZL){
            [[SEGSaveorupdateleaseManager sharedManager] requestSaveorupdateleaseWithParams:self.requestParams Finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                [subscriber sendNext:errorMessage];
                if (!isSuccessed) {
                    return;
                }
                [[NSNotificationCenter defaultCenter] postNotificationName:@"SEGUserHouseChangeNotification" object:nil];
                [subscriber sendCompleted];
                
            }];
        }
        if(self.type == SEGEnumPublishHouseTypeCS){
            [[SEGSaveorupdateleaseManager sharedManager] requestSaveOrUpdateSellWithParams:self.requestParams Finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                [subscriber sendNext:errorMessage];
                if (!isSuccessed) {
                    return;
                }
                [[NSNotificationCenter defaultCenter] postNotificationName:@"SEGUserHouseChangeNotification" object:nil];
                [subscriber sendCompleted];
            }];
        }
        return nil;
    }];
    return signal;
}


- (RACSignal *)sendSaveImageRequestWithPhotos:(NSArray<UIImage *> *)photos {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        if (self.imageData.count >= 9) {
            [subscriber sendCompleted];
        }
        @weakify(self)
        [[SEGMultipartfileuploadManager sharedManager] requestMultipartfileuploadWithImage:photos progress:nil completed:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
            @strongify(self)
            if (isSuccessed) {
                NSMutableArray<NSString*> *arrM = [NSMutableArray arrayWithArray:self.imageData];
                NSArray *imagesArr = (NSArray*)[result valueForKey:@"data"];
                [arrM addObjectsFromArray:imagesArr];
                self.imageData = [NSArray arrayWithArray:arrM];
                [subscriber sendCompleted];
            }else {
                NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:errorMessage}];
                [subscriber sendError:error];
            }
        }];
        
        return nil;
    }];
    return signal;
}



#pragma mark - custom delegate

#pragma mark - system delegate

#pragma mark - event response
- (void)destroyResource {
    [SEGDetailsellManager destroyResource];
}
#pragma mark - private methods
//组装列表数据
- (void)creatCellData {
    SEGDetailsellDataModel *editData;
    if (self.type == SEGEnumPublishHouseTypeCS) editData = [SEGDetailsellManager sharedManager].detailSell.data;
    if (self.type == SEGEnumPublishHouseTypeZL) editData = [SEGDetailsellManager sharedManager].detailLease.data;
    
    NSMutableArray *arrRow1 = [NSMutableArray array];
    {
        //如果是租赁的话 添加出租类型
        if (self.type == SEGEnumPublishHouseTypeZL) {
            SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
            data.title = @"出租类型";
            data.placeholder = @"请选择出租类型";
            data.paraKey = @"RENTAL_TYPE";
            if (self.reantType == SEGEnumReantType_Edit) {
                [self.requestParams setValue:editData.rentalType forKey:@"rentalType"];
                //                    租售类型 1:整租 2:独立房间 3:合租床位 4:出售
                if ([editData.rentalType isEqualToString:@"1"]) {
                    data.content = @"整租";
                }else if ([editData.rentalType isEqualToString:@"2"]) {
                    data.content = @"独立房间";
                }else if ([editData.rentalType isEqualToString:@"3"]) {
                    data.content = @"合租床位";
                }else if ([editData.rentalType isEqualToString:@"4"]) {
                    data.content = @"出售";
                }else {
                    data.content = @"";
                }
            }
            SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_NO];
            [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
            
        }
        
        if(self.reantType == SEGEnumReantType_Publish){
            SEGProfileHouselistModel *house = [SEGProfileManager sharedManager].profile.houseList.firstObject;
            
            SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
            data.title = @"房屋";
            data.placeholder = @"请选择房屋";
            data.content = house.houseName;
            data.paraKey = @"HOUSE";
            SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type: SEGEnumPublishHouseViewType_NO];
            [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
            
            [self.requestParams setValue:house.buildId forKey:@"buildId"];
            [self.requestParams setValue:house.unitId forKey:@"unitId"];
            [self.requestParams setValue:house.houseId forKey:@"houseId"];
            [self.requestParams setValue:house.communityId forKey:@"communityId"];
        }else{
            SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
            data.title = @"房屋";
            data.placeholder = @"请选择房屋";
            data.content = editData.houseName;
            data.paraKey = @"HOUSE";
            SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type: SEGEnumPublishHouseViewType_NO_Edit];
            [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
            
            [self.requestParams setValue:editData.buildId forKey:@"buildId"];
            [self.requestParams setValue:editData.unitId forKey:@"unitId"];
            [self.requestParams setValue:editData.houseId forKey:@"houseId"];
            [self.requestParams setValue:editData.communityId forKey:@"communityId"];
        }
    }
    
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = @"面积";
        data.content = @"m²";
        data.paraKey = @"AREA";
        data.textFieldPlaceholder = @"请输入房屋面积";
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content2 = editData.area;
            [self.requestParams setValue:editData.area forKey:@"area"];
        }
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_TextField_DecimalPad];
        [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = @"户型";
        data.placeholder = @"请选择户型";
        data.paraKey = @"HOUSE_TYPE";
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content = [NSString stringWithFormat:@"%@室%@厅%@卫",editData.room,editData.hall,editData.toilet];
            [self.requestParams setValue:editData.room forKey:@"room"];
            [self.requestParams setValue:editData.hall forKey:@"hall"];
            [self.requestParams setValue:editData.toilet forKey:@"toilet"];
        }
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_NO];
        [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = @"楼层";
        data.textFieldPlaceholder = @"所在楼层";
        data.textFieldPlaceholder2 = @"总楼层";
        data.paraKey = @"BUILDING_FLOOR";
        data.paraKey2 = @"BUILDING_FLOOR_TOTAL";
        
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content = editData.floor;
            data.content2 = editData.totalFloor;
            [self.requestParams setValue:editData.floor forKey:@"floor"];
            [self.requestParams setValue:editData.totalFloor forKey:@"totalFloor"];
        }
        
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_TextField_NumbersAndPunctuation];
        [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = self.type == SEGEnumPublishHouseTypeZL ? @"租金" : @"售价";
        data.content = self.type == SEGEnumPublishHouseTypeZL ? @"元/月" : @"万";
        data.textFieldPlaceholder = self.type == SEGEnumPublishHouseTypeZL ? @"请输入期望租金":@"请输入期望售价";
        data.paraKey = @"RENT";
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content2 = editData.price;
            [self.requestParams setValue:editData.price forKey:@"price"];
        }
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_TextField_DecimalPad];
        [arrRow1 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    
    NSMutableArray *arrRow2 = [NSMutableArray array];
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = @"标题";
        data.textFieldPlaceholder = @"如海文花园两房两厅 精装修 整租 近地铁";
        data.paraKey = @"TITLE";
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content2 = editData.rentalTitle;
            [self.requestParams setValue:editData.rentalTitle forKey:@"rentalTitle"];
        }
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_Title];
        [arrRow2 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.paraKey = @"CONTENT";
        data.textFieldPlaceholder = @"详细描述您的房源信息，有助于成交，比如房屋内部设施情况，交通位置等，注意事项等";
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content2 = editData.rentalDesc;
            [self.requestParams setValue:editData.rentalDesc forKey:@"rentalDesc"];
        }
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_Content];
        [arrRow2 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    
    NSMutableArray *arrRow3 = [NSMutableArray array];
    
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = @"电梯";
        data.placeholder = @"请选择是否有电梯";
        data.paraKey = @"ELEVATOR";
        
        if (self.reantType == SEGEnumReantType_Edit) {
            data.content = [editData.isElevator isEqualToString:@"1"] ? @"有电梯":@"无电梯";
            [self.requestParams setValue:editData.isElevator forKey:@"isElevator"];
        }
        
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_NO];
        [arrRow3 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    {
        SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
        data.title = @"装修程度";
        data.placeholder = @"请选择装修程度";
        data.paraKey = @"DECORRATION";
        
        if (self.reantType == SEGEnumReantType_Edit) {
            __block NSString *decorationLevelString = @"";
            NSArray<SEGQuerydictlistDictlistModel*> *decorationLevel = [self.selectedData valueForKey:@"decorationLevel"];
            [decorationLevel enumerateObjectsUsingBlock:^(SEGQuerydictlistDictlistModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj.code isEqualToString:editData.decorationLevel]) {
                    decorationLevelString = obj.name;
                    *stop = YES;
                    return;
                }
            }];
            data.content = decorationLevelString;
            [self.requestParams setValue:editData.decorationLevel forKey:@"decorationLevel"];
        }
        
        SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_NO];
        [arrRow3 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
    }
    if (self.type == SEGEnumPublishHouseTypeZL) {
        {
            SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
            data.title = @"押金模式";
            data.placeholder = @"请选择押金模式";
            data.paraKey = @"DEPOSIT";
            
            if (self.reantType == SEGEnumReantType_Edit) {
                __block NSString *depositModeString = @"";
                NSArray<SEGQuerydictlistDictlistModel*> *decorationLevel = [self.selectedData valueForKey:@"depositMode"];
                [decorationLevel enumerateObjectsUsingBlock:^(SEGQuerydictlistDictlistModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj.code isEqualToString:editData.depositMode]) {
                        depositModeString = obj.name;
                        *stop = YES;
                        return;
                    }
                }];
                data.content = depositModeString;
                [self.requestParams setValue:editData.depositMode forKey:@"depositMode"];
            }
            
            SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_NO];
            [arrRow3 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
        }
        {
            SEGPublishHouseViewModel *data = [[SEGPublishHouseViewModel alloc]init];
            data.title = @"入住时间";
            data.placeholder = @"请选择入住时间";
            data.paraKey = @"CHECK_IN";
            
            if (self.reantType == SEGEnumReantType_Edit) {
                __block NSString *checkInTimeString = @"";
                NSArray<SEGQuerydictlistDictlistModel*> *checkInTime = [self.selectedData valueForKey:@"checkInTime"];
                [checkInTime enumerateObjectsUsingBlock:^(SEGQuerydictlistDictlistModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj.code isEqualToString:editData.depositMode]) {
                        checkInTimeString = obj.name;
                        *stop = YES;
                        return;
                    }
                }];
                data.content = checkInTimeString;
                [self.requestParams setValue:editData.checkInTime forKey:@"checkInTime"];
            }
            
            SEGPublishHouseViewLayout *layout = [[SEGPublishHouseViewLayout alloc]initWithData:data type:SEGEnumPublishHouseViewType_NO];
            [arrRow3 addObject:@{@"Indetifier":SEGPublishHouseViewCellIndetifier,@"data":layout}];
        }
        {
            NSArray<NSString*> *houseFacilityString = [NSArray array];
            if (editData && editData.houseFacility) {
                houseFacilityString = [editData.houseFacility componentsSeparatedByString:@","];
                [self.requestParams setValue:editData.houseFacility forKey:@"houseFacility"];
            }
            
            NSMutableArray *houseFacilityM = [NSMutableArray array];
            NSArray<SEGQuerydictlistDictlistModel*> *houseFacility = [self.selectedData valueForKey:@"houseFacility"];
            [houseFacility enumerateObjectsUsingBlock:^(SEGQuerydictlistDictlistModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [houseFacilityM addObject:@{@"name":obj.name,@"code":obj.code,@"isSelected":(self.reantType == SEGEnumReantType_Edit && [houseFacilityString containsObject:obj.code]) ? @(YES): @(NO)}];
            }];
            self.selectedTags = [NSArray arrayWithArray:houseFacilityM];
            
            SEGPublishHouseTagViewModel *data = [[SEGPublishHouseTagViewModel alloc]init];
            data.title = @"房屋配置";
            data.tags = houseFacilityM;
            SEGPublishHouseTagViewLayout *layout = [[SEGPublishHouseTagViewLayout alloc]initWithData:data type:SEGEnumPublishHouseTagViewType_NO];
            [arrRow3 addObject:@{@"Indetifier":SEGPublishHouseTagViewCellIndetifier ,@"data":layout}];
        }
    }
    {
        SEGImageChooseViewModel *data = [[SEGImageChooseViewModel alloc]init];
        data.title = @"房屋照片";
        data.desc = @"(最多9张)";
        
        __block NSMutableArray<NSString*> *urlArray = [NSMutableArray array];
        [[editData.housePhoto componentsSeparatedByString:@","] enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj length] > 0) [ urlArray addObject:obj];
        }];
        self.imageData = urlArray;
        SEGImageChooseViewLayout *layout = [[SEGImageChooseViewLayout alloc]initWithData:data type:SEGEnumImageChooseViewType_THREE];
        [arrRow3 addObject:@{@"Indetifier":SEGImageChooseViewCellIndetifier ,@"data":layout}];
    }
    
    self.dataSoure = @[arrRow1,arrRow2,arrRow3];
    
}

- (RACSignal *)checkParams {
    @weakify(self);
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        @strongify(self);
        
        SEGDetailsellDataModel *editData;
        if (self.type == SEGEnumPublishHouseTypeCS) editData = [SEGDetailsellManager sharedManager].detailSell.data;
        if (self.type == SEGEnumPublishHouseTypeZL) editData = [SEGDetailsellManager sharedManager].detailLease.data;
        
        [self.requestParams setValue:@"2" forKey:@"publisherType"]; //发布人类型 1:后台物业员工 2:业主
        [self.requestParams setValue:@"1" forKey:@"advisoryType"]; //咨询类型 1:物业管理处 2:业主
        [self.requestParams setValue:@"2" forKey:@"releaseType"]; //发布状态 1:草稿 2:待审核 3:审核不通过 4:已放盘 5:下架
        
        if (self.reantType == SEGEnumReantType_Publish) {
            [self.requestParams setValue:self.rentalType forKey:@"rentalType"];// 租售类型 1:整租 2:独立房间 3:合租床位 4:出售
            [self.requestParams setValue:@"0" forKey:@"rentalId"]; //房屋租售主键ID,新增传0
            [self.requestParams setValue:@"0" forKey:@"leaseId"];  //房屋出租主键ID,新增传0
        }else{
            [self.requestParams setValue:self.rentalType forKey:@"rentalType"];// 租售类型 1:整租 2:独立房间 3:合租床位 4:出售
            [self.requestParams setValue:editData.rentalId forKey:@"rentalId"]; //房屋租售主键ID,新增传0
            [self.requestParams setValue:editData.leaseId forKey:@"leaseId"];  //房屋出租主键ID,新增传0
        }
        
        // 出租类型
        if (![[self.requestParams allKeys] containsObject:@"rentalType"] || [[self.requestParams valueForKey:@"rentalType"] length] <= 0) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请选择出租类型"}]];
            return nil;
        }
        
        // 面积
        if (![[self.requestParams allKeys] containsObject:@"area"] || [[self.requestParams valueForKey:@"area"] length] <= 0) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入面积"}]];
            return nil;
        }
        
        if ([[self.requestParams valueForKey:@"area"] floatValue] <= 0.0001) { 
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入正确的面积"}]];
            return nil;
        }
        
        //户型
        if (!([[self.requestParams allKeys] containsObject:@"room"] &&
              [[self.requestParams allKeys] containsObject:@"hall"] &&
              [[self.requestParams allKeys] containsObject:@"toilet"])) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入户型"}]];
            return nil;
        }
        
        //楼层
        if (!([[self.requestParams allKeys] containsObject:@"floor"] &&
              [[self.requestParams allKeys] containsObject:@"totalFloor"])) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入楼层"}]];
            return nil;
        }
        if ([[self.requestParams valueForKey:@"floor"] length] <= 0 ||
            [[self.requestParams valueForKey:@"totalFloor"] length] <= 0) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入楼层"}]];
            return nil;
        }
        int floor = abs([[NSNumber numberWithString:[self.requestParams valueForKey:@"floor"]] intValue]);
        int totalFloor = abs([[NSNumber numberWithString:[self.requestParams valueForKey:@"totalFloor"]] intValue]);
        if (floor == 0 || totalFloor == 0 || (floor > totalFloor)) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入正确的楼层"}]];
            return nil;
        }
        
        //价格
        if (![[self.requestParams allKeys] containsObject:@"price"]||[[self.requestParams valueForKey:@"price"] length] <= 0 ) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入价格"}]];
            return nil;
        }
        if ([[self.requestParams valueForKey:@"price"] floatValue] <= 0.0001) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入正确的金额"}]];
            return nil;
        }
        
        //房源标题
        if (!([[self.requestParams allKeys] containsObject:@"rentalTitle"] && [[self.requestParams valueForKey:@"rentalTitle"] length] > 0)) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入房源标题"}]];
            return nil;
        }
        
        //房源描述
        if (!([[self.requestParams allKeys] containsObject:@"rentalDesc"] && [[self.requestParams valueForKey:@"rentalDesc"] length] > 0)) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请输入房源描述"}]];
            return nil;
        }
        
        //电梯
        if (![[self.requestParams allKeys] containsObject:@"isElevator"]) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请选择电梯情况"}]];
            return nil;
        }
        
        //装修程度
        if (![[self.requestParams allKeys] containsObject:@"decorationLevel"]) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请选择装修程度"}]];
            return nil;
        }
        
        if(self.type == SEGEnumPublishHouseTypeZL){
            //押金模式
            if (![[self.requestParams allKeys] containsObject:@"depositMode"]) {
                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请选择押金模式"}]];
                return nil;
            }
            
            //入住时间
            if (![[self.requestParams allKeys] containsObject:@"checkInTime"]) {
                [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请选择入住时间"}]];
                return nil;
            }
            
            //房屋配置
            __block NSMutableArray *codeM = [NSMutableArray array];
            [self.selectedTags enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([[obj valueForKey:@"isSelected"] boolValue]) [codeM addObject:[obj valueForKey:@"code"]];
            }];
            //2.2.0 去掉必选
            //        if (codeM.count <= 0) {
            //            [SEGAlertView showTmepMessageWithMessage:@"请选择房屋配置"];
            //            return;
            //        }
            [self.requestParams setValue:[codeM componentsJoinedByString:@","] forKey:@"houseFacility"];
        }
        
        //照片
        if (self.imageData.count <= 0) {
            [subscriber sendError:[NSError errorWithDomain:NSURLErrorDomain code:100 userInfo:@{NSLocalizedDescriptionKey:@"请上传房屋照片"}]];
            return nil;
        }
        
        // 显示loading
        [subscriber sendNext:@(1)];
        [subscriber sendCompleted];
        
        return nil;
    }];
    return signal;
    
}


#pragma mark - setter and getter

@end
